package com.scpii.universal.util;

import java.io.File;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class UtilTool {

	private static SimpleDateFormat dateFormat = new SimpleDateFormat(
			"yyyy-MM-dd HH:mm:ss");

	/**
	 * 将String转换成Integer
	 * 
	 * @param strs
	 * @return
	 */
	public static Integer StringToInteger(String strs) {
		if (strs != null) {
			try {
				return Integer.parseInt(strs);
			} catch (Exception e) {
				e.printStackTrace();
				return 0;
			}
		}
		return 0;
	}

	/**
	 * 将Object转换成Integer
	 * 
	 * @param obj
	 * @return
	 */
	public static Integer ObjectToInteger(Object obj) {
		if (obj != null) {
			try {
				return (Integer) obj;
			} catch (Exception e) {
				e.printStackTrace();
				return 0;
			}
		}
		return 0;
	}

	/**
	 * 日期转换成字符串
	 */
	public static String dateToString(Date date) {
		if (date != null) {
			return dateFormat.format(date);
		}
		return null;
	}

	/**
	 * 字符串转换成日期
	 * 
	 * @param dateStr
	 * @return
	 */
	public static Date stringToDate(String dateStr) {
		if (dateStr != null) {
			try {
				if (dateStr.length() == 10) {
					dateFormat = new SimpleDateFormat("yyyy-MM-dd");
					Date date = dateFormat.parse(dateStr);
					return date;
				} else if (dateStr.length() > 10) {
					Date date = dateFormat.parse(dateStr);
					return date;
				}
			} catch (ParseException e) {
				e.printStackTrace();
				return null;
			}
		}
		return null;
	}

	/**
	 * 用于删除文件
	 * 
	 * @param path
	 * @throws Exception
	 */
	public static void deleteFile(String path) {
		if (path != null) {
			File file = new File(path);
			boolean bool = file.delete();
			System.out.println(bool);
		}
	}
}
